/*
Kakine
ActionScript Framework
Copyright © 2011, PUNY, LLC.

This file is part of KAKINE.

KAKINE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

KAKINE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KAKINE.  If not, see <http://www.gnu.org/licenses/>.
*/ 
package com.puny.utils
{
	public class CommaPadding extends Object
	{
		public function CommaPadding()
		{
			super();
		}

		public static function format(src:int):String {
			var plus:Boolean = src >= 0;
			var value:uint = plus? src : -src;
			var string:String = "";
			do {
				var part:uint = value % 1000;
				value = uint(value / 1000);
				string = (value > 0 ? padding(part) : part.toString()) + (string.length > 0 ? "," : "") + string;
			} while(value > 999);
			if (value > 0) {
				string = value.toString() + (string.length > 0 ? "," : "") + string;
			}
			return (plus? "" : "-") + string;
			
		}
		
		private static function padding(value:uint):String {
			var string:String = "";
			if (value < 10) {
				string += "0";
			}
			if (value < 100) {
				string += "0";
			}
			string += value.toString();
			return string;
		}
	}
}